home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / graphics / icontools / ficon11.lha / ForceIcon / Source / ForceIcon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-04  |  23.4 KB  |  1,030 lines

  1. /*
  2. Auto:        smake    ForceIcon
  3. */
  4.  
  5. /* $Revision Header built automatically *************** (do not edit) ************
  6. **
  7. ** © Copyright by GuntherSoft
  8. **
  9. ** File             : SnakeSYS:CPrgs/Utils/ForceIcon.c
  10. ** Created on       : Wednesday, 20.10.93 15:55:50
  11. ** Created by       : Kai Iske
  12. ** Current revision : V1.0
  13. **
  14. **
  15. ** Purpose
  16. ** -------
  17. **   - Forces Disk Icons to a specified position.
  18. **     Usefull for CD-Rom users
  19. **
  20. ** Revision V1.0
  21. ** --------------
  22. ** created on Wednesday, 20.10.93 15:55:50  by  Kai Iske.   LogMessage :
  23. **     --- Initial release ---
  24. **
  25. *********************************************************************************/
  26.  
  27.  
  28.  
  29. /**********************************************************************/
  30. /*                        External references                         */
  31. /**********************************************************************/
  32. extern struct    Window        *MainWinHandle;        // Window handles
  33. extern struct    Window        *EditWinHandle;
  34. extern struct    Window        *PosWinHandle;
  35. extern struct    Window        *ManWinHandle;
  36.  
  37.  
  38.  
  39.  
  40.  
  41. /**********************************************************************/
  42. /*                           Library bases                            */
  43. /**********************************************************************/
  44. struct    ExecBase    *SysBase;
  45. struct    IntuitionBase    *IntuitionBase    = NULL;
  46. struct    Library        *DiskfontBase    = NULL;
  47. struct    GfxBase        *GfxBase    = NULL;
  48. struct    Library        *GadToolsBase    = NULL;
  49. struct    DosLibrary    *DOSBase    = NULL;
  50. struct    Library        *IconBase    = NULL;
  51. struct    Library        *UtilityBase    = NULL;
  52. struct    Library        *CxBase        = NULL;
  53. struct    Library        *IFFParseBase    = NULL;
  54. struct    Library        *AslBase    = NULL;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. /**********************************************************************/
  62. /*                         Broker Definition                          */
  63. /**********************************************************************/
  64. struct NewBroker BrokerDef =
  65. {
  66.     NB_VERSION,
  67.     "ForceIcon",
  68.     "ForceIcon v"REVISION,
  69.     "Forces icons to abolute position",
  70.     NBU_NOTIFY|NBU_UNIQUE,
  71.     COF_SHOW_HIDE,
  72.     0,
  73.     NULL,
  74.     0
  75. };
  76.  
  77.  
  78.  
  79. /**********************************************************************/
  80. /*                        Commandline template                        */
  81. /**********************************************************************/
  82. static const char    *Template = "CX_PRIORITY/K/N,CX_POPUP/K,CX_POPKEY/K";
  83. enum    {PRI_ARG, POP_ARG, KEY_ARG, LAST_ARG};
  84.  
  85.  
  86. /**********************************************************************/
  87. /*                         "No-StartUp vars"                          */
  88. /**********************************************************************/
  89. static const char    _VER[] = "\0$VER: ForceIcon "REVISION" ("REVDATE")\0";
  90. char    _ProgramName[] = "ForceIcon";
  91. LONG    _OSERR = 0;
  92.  
  93. /**********************************************************************/
  94. /*                          Global variables                          */
  95. /**********************************************************************/
  96. static    ULONG    __asm (*OldGetIcon)(register __a0 UBYTE *, register __a1 struct DiskObject *, register __a2 struct FreeList *, register __a6 struct Library *);
  97. static    ULONG    __asm (*OldLock)(register __d1 UBYTE *, register __d2 ULONG, register __a6 struct DosLibrary *);
  98.  
  99. struct    List        VolumeList;            // List of patched volumes
  100. struct    SignalSemaphore    MySemaphore;            // My beautiful semaphore
  101. struct    WBStartup    *_WBenchMsg    = NULL;        // StartUp message
  102. struct    IClass        *GetFileClass;            // ImageClass for GetFile
  103. static    UWORD    Active = TRUE;                // State of Broker
  104.  
  105.  
  106.  
  107.  
  108.  
  109. /**********************************************************************/
  110. /*                      This is our main program                      */
  111. /**********************************************************************/
  112. ULONG __saveds main(void)
  113. {
  114.     struct    Class        *InitGetFile(void);
  115.     struct    Process        *MyProc;
  116.     struct    MsgPort        *BrokerPort;
  117.     CxObj            *InputBroker;
  118.     CxObj            *InputKey;
  119.     ULONG            Error, Pri = 0;
  120.     char            HotKeyDef[128];
  121.     BOOL            PopUp = TRUE;
  122.  
  123.         // Get SysBase
  124.  
  125.     SysBase    = *((struct ExecBase **)0x4L);
  126.  
  127.         // Get address of our process
  128.  
  129.     MyProc = (struct Process *)FindTask(NULL);
  130.  
  131.         // Determine where we were started from
  132.  
  133.     if(!MyProc->pr_CLI)
  134.         _WBenchMsg = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
  135.  
  136.         // Initialize our semaphore
  137.  
  138.     InitSemaphore(&MySemaphore);
  139.  
  140.         // Open libraries
  141.  
  142.     if(OpenAll())
  143.     {
  144.             // Check for tooltypes or Commandline args
  145.  
  146.         if(CheckToolTypes(HotKeyDef, &Pri, &PopUp))
  147.         {
  148.             if((GetFileClass = (struct IClass *)InitGetFile()))
  149.             {
  150.                     // Load in preferences
  151.  
  152.                 LoadPrefs();
  153.  
  154.                     // Create our Message Port for the Broker
  155.  
  156.                 if((BrokerPort = CreateMsgPort()))
  157.                 {
  158.                         // Set up additional fields within broker structure
  159.  
  160.                     BrokerDef.nb_Port    = BrokerPort;
  161.                     BrokerDef.nb_Pri    = Pri;
  162.  
  163.                         // Create broker
  164.  
  165.                     if((InputBroker = CxBroker(&BrokerDef, (LONG *)&Error)))
  166.                     {
  167.                             // Create HotKey
  168.  
  169.                         if((InputKey = HotKey(HotKeyDef, BrokerPort, POPKEY)))
  170.                         {
  171.                                 // Attach HotKey to Broker
  172.  
  173.                             AttachCxObj(InputBroker, InputKey);
  174.  
  175.                                 // Activate Broker
  176.  
  177.                             ActivateCxObj(InputBroker, TRUE);
  178.  
  179.                             Forbid();
  180.                                 // Patch icon.library functions
  181.  
  182.                             OldGetIcon        = (ULONG *)SetFunction(IconBase, -0x0000002a, &MyGetIcon);
  183.  
  184.                                 // Patch dos.library functions
  185.  
  186.                             OldLock            = (ULONG *)SetFunction(DOSBase, -0x00000054, &MyLock);
  187.                             Permit();
  188.  
  189.                                 // PopUp main window ???
  190.  
  191.                             if(PopUp)
  192.                                 OpenMainWin();
  193.  
  194.                                 // Handle all inputs
  195.  
  196.                             HandleInput(BrokerPort, InputBroker);
  197.  
  198.  
  199.                             Forbid();
  200.                                 // Reinstall old icon.library functions
  201.  
  202.                             SetFunction(IconBase, -0x0000002a, OldGetIcon);
  203.  
  204.                                 // Restore DOS-Library functions
  205.  
  206.                             SetFunction(DOSBase, -0x00000054, OldLock);
  207.                             Permit();
  208.                         }
  209.  
  210.                             // Dispose Broker
  211.  
  212.                         DeleteCxObjAll(InputBroker);
  213.                     }
  214.  
  215.                         // Remove Msg-Port
  216.  
  217.                     DeleteMsgPort(BrokerPort);
  218.                 }
  219.                     // Free list of patches
  220.  
  221.                 FreeDevVolList(&VolumeList);
  222.  
  223.                     // Dispose GetFile class
  224.  
  225.                 FreeClass(GetFileClass);
  226.             }
  227.             else
  228.                 DisplayError(ERR_NOFILE, NULL);
  229.         }
  230.     }
  231.  
  232.         // Close libs
  233.  
  234.     CloseAll();
  235.  
  236.         // Send back WBStartUp Message
  237.  
  238.     if(_WBenchMsg)
  239.     {
  240.         Forbid();
  241.         ReplyMsg((struct Message *)_WBenchMsg);
  242.     }
  243.     return(0);
  244. }
  245.  
  246.  
  247. /**********************************************************************/
  248. /*                        Functionreplacements                        */
  249. /**********************************************************************/
  250. void chkabort(void){;}
  251. void __stdargs _XCEXIT(LONG Val){;}
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258. /**********************************************************************/
  259. /*                        Check for ToolTypes                         */
  260. /**********************************************************************/
  261. BOOL CheckToolTypes(char *HotKeyDef, ULONG *Pri, BOOL *PopUp)
  262. {
  263.         // set default PopUp HotKey
  264.  
  265.     strcpy(HotKeyDef, "lalt lshift i");
  266.  
  267.  
  268.         // Did we come from WB ???
  269.  
  270.     if(_WBenchMsg)
  271.     {
  272.         struct    WBArg        *MyArg = _WBenchMsg->sm_ArgList;
  273.         struct    DiskObject    *MyObj;
  274.         char    **ToolTypes, *ThisTool;
  275.  
  276.             // Switch to currentdir
  277.  
  278.         CurrentDir(MyArg->wa_Lock);
  279.  
  280.             // Try to get our icon
  281.  
  282.         if((MyObj = GetDiskObjectNew(MyArg->wa_Name)))
  283.         {
  284.                 // Get tooltypes
  285.  
  286.             if((ToolTypes = MyObj->do_ToolTypes))
  287.             {
  288.                     // Parse ToolTypes
  289.  
  290.                 if((ThisTool = FindToolType(ToolTypes, "CX_PRIORITY")))
  291.                 {
  292.                     char    *Dummy;
  293.  
  294.                     *Pri = strtol(ThisTool, &Dummy, 10);
  295.                 }
  296.  
  297.                 if((ThisTool = FindToolType(ToolTypes, "CX_POPUP")))
  298.                     *PopUp = !(MatchToolValue(ThisTool, "NO"));
  299.  
  300.                 if((ThisTool = FindToolType(ToolTypes, "CX_POPKEY")))
  301.                     strncpy(HotKeyDef, ThisTool, 127);
  302.             }
  303.  
  304.                 // Free our DiskObject again
  305.  
  306.             FreeDiskObject(MyObj);
  307.         }
  308.         return(TRUE);
  309.     }
  310.     else
  311.     {
  312.         APTR    *Args;
  313.         struct    RDArgs    *MyRDArgs;
  314.         BOOL    GoOn = FALSE;
  315.  
  316.             // Try to allocate buffer for ReadArgs
  317.  
  318.         if((Args = AllocVec((sizeof(ULONG) * LAST_ARG), MEMF_CLEAR)))
  319.         {
  320.                 // Parse commandline
  321.  
  322.             if((MyRDArgs = ReadArgs((char *)Template, (LONG *)Args, NULL)))
  323.             {
  324.                 GoOn = TRUE;
  325.  
  326.                 if(Args[PRI_ARG])
  327.                     *Pri = *(ULONG *)Args[PRI_ARG];
  328.  
  329.                 if(Args[POP_ARG])
  330.                 {
  331.                     if(!stricmp(Args[POP_ARG], "NO"))
  332.                         *PopUp = FALSE;
  333.                 }
  334.  
  335.                 if(Args[KEY_ARG])
  336.                     strncpy(HotKeyDef, Args[KEY_ARG], 127);
  337.  
  338.                 FreeArgs(MyRDArgs);
  339.             }
  340.             else
  341.                 PrintFault(IoErr(), "ForceIcon ");
  342.  
  343.             FreeVec(Args);
  344.         }
  345.         else
  346.             PrintFault(ERROR_NO_FREE_STORE, "ForceIcon ");
  347.  
  348.         return(GoOn);
  349.     }
  350. }
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. /**********************************************************************/
  359. /*                      My new GetIcon function                       */
  360. /**********************************************************************/
  361. ULONG __saveds __asm MyGetIcon(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase)
  362. {
  363.     struct    Process        *MyProc = (struct Process *)FindTask(NULL);
  364.     ULONG    RetVal;
  365.  
  366.         // Calling process a real process and is it Workbench ?
  367.  
  368.     if((MyProc->pr_Task.tc_Node.ln_Type == NT_PROCESS) && !strcmp(MyProc->pr_Task.tc_Node.ln_Name, "Workbench"))
  369.     {
  370.             if(!stricmp(Name, "Disk"))
  371.                 RetVal = DoForce(Name, DObj, FList, IconBase);
  372.             else
  373.                 RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  374.     }
  375.     else
  376.         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  377.  
  378.     return(RetVal);
  379. }
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386. /**********************************************************************/
  387. /*                       Main forcement routine                       */
  388. /**********************************************************************/
  389. ULONG __asm DoForce(register __a0 UBYTE *Name, register __a1 struct DiskObject *DObj, register __a2 struct FreeList *FList, register __a6 struct Library *IconBase)
  390. {
  391.     struct    FileLock    *Dir;
  392.     struct    DosList        *DList;
  393.     char    VolName[130], DevName[130];
  394.     BPTR    MyLock, CheckLock;
  395.     ULONG    RetVal = 0;
  396.     BOOL    Found = FALSE;
  397.  
  398.         // Get our semaphore
  399.  
  400.     ObtainSemaphore(&MySemaphore);
  401.  
  402.         // Are we active ???
  403.  
  404.     if(Active)
  405.     {
  406.             // Switch to current dir
  407.  
  408.         MyLock    = CurrentDir(NULL);
  409.         Dir    = (struct FileLock *)BADDR(MyLock);
  410.         DList    = (struct DosList *)BADDR(Dir->fl_Volume);
  411.  
  412.             // Get name of volume inserted
  413.  
  414.         setmem(VolName, 130, 0);
  415.         setmem(DevName, 130, 0);
  416.         strncpy(VolName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  417.  
  418.             // Reset current dir
  419.  
  420.         CurrentDir(MyLock);
  421.  
  422.             // Get Name of Device
  423.  
  424.         if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  425.         {
  426.             while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  427.             {
  428.                 if(Dir->fl_Task == DList->dol_Task)
  429.                     strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  430.             }
  431.             UnLockDosList(LDF_DEVICES|LDF_READ);
  432.         }
  433.  
  434.             // Really to load from ROOT ???
  435.  
  436.         if(!(CheckLock = ParentDir(MyLock)))
  437.         {
  438.                 // Do we have patches waiting ???
  439.  
  440.             if(!IsListEmpty(&VolumeList))
  441.             {
  442.                 struct    VolEntry    *ThisEntry = (struct VolEntry *)VolumeList.lh_Head;
  443.  
  444.                 do
  445.                 {
  446.                         // This one to patch ???
  447.  
  448.                     if(ThisEntry->Link.ln_Type == LDF_DEVICES && !stricmp(ThisEntry->VolName, DevName))
  449.                         Found = TRUE;
  450.  
  451.                     else if(ThisEntry->Link.ln_Type == LDF_VOLUMES && !stricmp(ThisEntry->VolName, VolName))
  452.                         Found = TRUE;
  453.  
  454.                     else
  455.                         ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  456.  
  457.                 } while(!Found && ThisEntry->Link.ln_Succ);
  458.  
  459.                     // Object to be patched ?
  460.  
  461.                 if(Found)
  462.                 {
  463.                         // Alternative icon ???
  464.  
  465.                     if(ThisEntry->UseAlt)
  466.                     {
  467.                         char    *End;
  468.  
  469.                             // Check for name and remove extension
  470.  
  471.                         strcpy(VolName, ThisEntry->IconName);
  472.                         strlwr(VolName);
  473.                         if((End = strstr(VolName, ".info")))
  474.                         {
  475.                             BPTR    TestLock;
  476.  
  477.                             setmem(VolName, 130, 0);
  478.                             strncpy(VolName, ThisEntry->IconName, (End - VolName));
  479.  
  480.                                 // Try to get supplied name
  481.  
  482.                             if((TestLock = Lock(ThisEntry->IconName, ACCESS_READ)))
  483.                             {
  484.                                 UnLock(TestLock);
  485.  
  486.                                     // Try to read in this icon
  487.  
  488.                                 if(!(RetVal = OldGetIcon(VolName, DObj, FList, IconBase)))
  489.                                     RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  490.                                 else
  491.                                 {
  492.                                         // Ok, we`ve loaded a new icon, so set appropriate flags ;)
  493.  
  494.                                     if(DObj->do_Type == WBTOOL || DObj->do_Type == WBPROJECT)
  495.                                     {
  496.                                             // Try to set drawerdata for tool and project icons
  497.  
  498.                                         if((DObj->do_DrawerData = AllocMem(sizeof(struct DrawerData), MEMF_CLEAR|MEMF_PUBLIC)))
  499.                                         {
  500.                                             struct    DrawerData    *DDat = DObj->do_DrawerData;
  501.  
  502.                                                 // Fill in structure
  503.  
  504.                                             DDat->dd_NewWindow.LeftEdge    = ThisEntry->LeftEdge;
  505.                                             DDat->dd_NewWindow.TopEdge    = ThisEntry->TopEdge;
  506.                                             DDat->dd_NewWindow.Width    = ThisEntry->Width;
  507.                                             DDat->dd_NewWindow.Height    = ThisEntry->Height;
  508.                                             DDat->dd_NewWindow.DetailPen    = 255;
  509.                                             DDat->dd_NewWindow.BlockPen    = 255;
  510.                                             DDat->dd_NewWindow.Flags    = WFLG_HASZOOM|WFLG_WINDOWTICKED|WFLG_REPORTMOUSE|WFLG_SIMPLE_REFRESH|WFLG_SIZEBRIGHT|WFLG_SIZEBBOTTOM|WFLG_CLOSEGADGET|WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_SIZEGADGET;
  511.                                             DDat->dd_NewWindow.MinWidth    = 90;
  512.                                             DDat->dd_NewWindow.MinHeight    = 40;
  513.                                             DDat->dd_NewWindow.MaxWidth    = 0xffff;
  514.                                             DDat->dd_NewWindow.MaxHeight    = 0xffff;
  515.  
  516.                                                 // A Ok, set new type of icon
  517.  
  518.                                             DObj->do_Type = WBDISK;
  519.                                         }
  520.                                     }
  521.                                     else
  522.                                         DObj->do_Type = WBDISK;
  523.                                 }
  524.                             }
  525.                             else
  526.                                 RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  527.                         }
  528.                         else
  529.                             RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  530.                     }
  531.                     else
  532.                         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  533.  
  534.                         // Patch position ???
  535.  
  536.                     if(RetVal)
  537.                     {
  538.                         struct    Screen    *WBScreen    = LockPubScreen("Workbench");
  539.  
  540.                         if(WBScreen)
  541.                         {
  542.                                 // Do so
  543.  
  544.                             DObj->do_CurrentX = (ThisEntry->IconPos) ? ThisEntry->Left : NO_ICON_POSITION;
  545.                             DObj->do_CurrentY = (ThisEntry->IconPos) ? ThisEntry->Top - WBScreen->BarHeight - 1 : NO_ICON_POSITION;
  546.  
  547.                             UnlockPubScreen(NULL, WBScreen);
  548.                         }
  549.                     }
  550.                 }
  551.             }
  552.         }
  553.         else
  554.             UnLock(CheckLock);
  555.     }
  556.  
  557.         // No entry found and not the orig. icon read -> use supplied name
  558.  
  559.     if(!Found && !RetVal)
  560.         RetVal = OldGetIcon(Name, DObj, FList, IconBase);
  561.  
  562.         // Release that fine semaphore
  563.  
  564.     ReleaseSemaphore(&MySemaphore);
  565.  
  566.     return(RetVal);
  567. }
  568.  
  569.  
  570.  
  571.  
  572.  
  573. /**********************************************************************/
  574. /*                        My new Lock routine                         */
  575. /**********************************************************************/
  576. ULONG __saveds __asm MyLock(register __d1 UBYTE *Name, register __d2 ULONG Mode, register __a6 struct DosLibrary *DOSBase)
  577. {
  578.     struct    Process        *MyProc = (struct Process *)FindTask(NULL);
  579.     struct    FileLock    *Dir;
  580.     struct    DosList        *DList;
  581.     char    VolName[130], DevName[130];
  582.     BPTR    MyLock, CheckLock;
  583.     ULONG    RetVal;
  584.     BOOL    Found = FALSE;
  585.  
  586.  
  587.         // Calling process a real process and is it Workbench ?
  588.  
  589.     if((MyProc->pr_Task.tc_Node.ln_Type == NT_PROCESS) && !strcmp(MyProc->pr_Task.tc_Node.ln_Name, "Workbench"))
  590.     {
  591.             // Trying to load a Disk.info ???
  592.  
  593.         if(!stricmp(Name, "Disk.info"))
  594.         {
  595.                 // Get my semaphore
  596.  
  597.             ObtainSemaphore(&MySemaphore);
  598.  
  599.                 // Broker active ???
  600.  
  601.             if(Active)
  602.             {
  603.                     // Switch to current dir
  604.  
  605.                 MyLock    = CurrentDir(NULL);
  606.                 Dir    = (struct FileLock *)BADDR(MyLock);
  607.                 DList    = (struct DosList *)BADDR(Dir->fl_Volume);
  608.  
  609.                     // Get name of volume inserted
  610.  
  611.                 setmem(VolName, 130, 0);
  612.                 setmem(DevName, 130, 0);
  613.                 strncpy(VolName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  614.  
  615.                     // Reset current dir
  616.  
  617.                 CurrentDir(MyLock);
  618.  
  619.                     // Get Name of Device
  620.  
  621.                 if((DList = LockDosList(LDF_DEVICES|LDF_READ)))
  622.                 {
  623.                     while((DList = NextDosEntry(DList, LDF_DEVICES|LDF_READ)))
  624.                     {
  625.                         if(Dir->fl_Task == DList->dol_Task)
  626.                             strncpy(DevName, ((char *)BADDR(DList->dol_Name) + 1), *((char *)BADDR(DList->dol_Name)));
  627.                     }
  628.                     UnLockDosList(LDF_DEVICES|LDF_READ);
  629.                 }
  630.  
  631.                     // Really load from ROOT ?
  632.  
  633.                 if(!(CheckLock = ParentDir(MyLock)))
  634.                 {
  635.                         // Do we have patches waiting ???
  636.  
  637.                     if(!IsListEmpty(&VolumeList))
  638.                     {
  639.                         struct    VolEntry    *ThisEntry = (struct VolEntry *)VolumeList.lh_Head;
  640.  
  641.                         do
  642.                         {
  643.                                 // This one to patch ???
  644.  
  645.                             if(ThisEntry->Link.ln_Type == LDF_DEVICES && !stricmp(ThisEntry->VolName, DevName))
  646.                                 Found = TRUE;
  647.  
  648.                             else if(ThisEntry->Link.ln_Type == LDF_VOLUMES && !stricmp(ThisEntry->VolName, VolName))
  649.                                 Found = TRUE;
  650.  
  651.                             else
  652.                                 ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  653.  
  654.                         } while(!Found && ThisEntry->Link.ln_Succ);
  655.  
  656.                             // Object to be patched ?
  657.  
  658.                         if(Found)
  659.                         {
  660.                                 // If an alternative icon is to be used
  661.                                 // lock this one, otherwise lock Disk.info
  662.  
  663.                             if(ThisEntry->UseAlt)
  664.                             {
  665.                                 struct    DiskObject    *OldDiskObject;
  666.                                 WORD    OldLeft = 50, OldTop = 50, OldWidth = 400, OldHeight = 100;
  667.  
  668.                                 if(!(RetVal = OldLock(ThisEntry->IconName, Mode, DOSBase)))
  669.                                     RetVal = OldLock(Name, Mode, DOSBase);
  670.                                 else
  671.                                 {
  672.                                         // Get original Disk.info file, in order to obtain
  673.                                         // the correct window position and size
  674.  
  675.                                     strcat(DevName, ":Disk");
  676.                                     if(!(OldDiskObject = GetDiskObject(DevName)))
  677.                                     {
  678.                                         strcat(VolName, ":Disk");
  679.                                         OldDiskObject = GetDiskObject(VolName);
  680.                                     }
  681.  
  682.                                     if(OldDiskObject)
  683.                                     {
  684.                                         OldLeft        = OldDiskObject->do_DrawerData->dd_NewWindow.LeftEdge;
  685.                                         OldTop        = OldDiskObject->do_DrawerData->dd_NewWindow.TopEdge;
  686.                                         OldWidth    = OldDiskObject->do_DrawerData->dd_NewWindow.Width;
  687.                                         OldHeight    = OldDiskObject->do_DrawerData->dd_NewWindow.Height;
  688.  
  689.                                         FreeDiskObject(OldDiskObject);
  690.                                     }
  691.  
  692.                                     ThisEntry->LeftEdge    = OldLeft;
  693.                                     ThisEntry->TopEdge    = OldTop;
  694.                                     ThisEntry->Width    = OldWidth;
  695.                                     ThisEntry->Height    = OldHeight;
  696.                                 }
  697.                             }
  698.                             else
  699.                                 Found = FALSE;
  700.                         }
  701.                     }
  702.                 }
  703.                 else
  704.                     UnLock(CheckLock);
  705.             }
  706.  
  707.             ReleaseSemaphore(&MySemaphore);
  708.         }
  709.     }
  710.  
  711.     if(!Found)
  712.         RetVal = OldLock(Name, Mode, DOSBase);
  713.  
  714.     return(RetVal);
  715. }
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722. /**********************************************************************/
  723. /*                           Open libraries                           */
  724. /**********************************************************************/
  725. BOOL OpenAll(void)
  726. {
  727.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)))
  728.     {
  729.         DisplayError(ERR_OPEN, (ULONG)"intuition.library");
  730.         return(FALSE);
  731.     }
  732.  
  733.     if(!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37)))
  734.     {
  735.         DisplayError(ERR_OPEN, (ULONG)"dos.library");
  736.         return(FALSE);
  737.     }
  738.  
  739.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37)))
  740.     {
  741.         DisplayError(ERR_OPEN, (ULONG)"graphics.library");
  742.         return(FALSE);
  743.     }
  744.  
  745.     if(!(GadToolsBase = OpenLibrary("gadtools.library", 37)))
  746.     {
  747.         DisplayError(ERR_OPEN, (ULONG)"gadtools.library");
  748.         return(FALSE);
  749.     }
  750.  
  751.     if(!(IconBase = OpenLibrary("icon.library", 37)))
  752.     {
  753.         DisplayError(ERR_OPEN, (ULONG)"icon.library");
  754.         return(FALSE);
  755.     }
  756.  
  757.     if(!(UtilityBase = OpenLibrary("utility.library", 37)))
  758.     {
  759.         DisplayError(ERR_OPEN, (ULONG)"utility.library");
  760.         return(FALSE);
  761.     }
  762.  
  763.     if(!(CxBase = OpenLibrary("commodities.library", 37)))
  764.     {
  765.         DisplayError(ERR_OPEN, (ULONG)"commodities.library");
  766.         return(FALSE);
  767.     }
  768.  
  769.     if(!(IFFParseBase = OpenLibrary("iffparse.library", 37)))
  770.     {
  771.         DisplayError(ERR_OPEN, (ULONG)"iffparse.library");
  772.         return(FALSE);
  773.     }
  774.  
  775.     if(!(DiskfontBase = OpenLibrary("diskfont.library", 36)))
  776.     {
  777.         DisplayError(ERR_OPEN, (ULONG)"diskfont.library");
  778.         return(FALSE);
  779.     }
  780.  
  781.     if(!(AslBase = OpenLibrary("asl.library", 36)))
  782.     {
  783.         DisplayError(ERR_OPEN, (ULONG)"asl.library");
  784.         return(FALSE);
  785.     }
  786.  
  787.     return(TRUE);
  788. }
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797. /**********************************************************************/
  798. /*                          Close libraries                           */
  799. /**********************************************************************/
  800. void CloseAll(void)
  801. {
  802.     if(AslBase)
  803.         CloseLibrary(AslBase);
  804.  
  805.     if(DiskfontBase)
  806.         CloseLibrary(DiskfontBase);
  807.  
  808.     if(IFFParseBase)
  809.         CloseLibrary(IFFParseBase);
  810.  
  811.     if(CxBase)
  812.         CloseLibrary(CxBase);
  813.  
  814.     if(UtilityBase)
  815.         CloseLibrary(UtilityBase);
  816.  
  817.     if(IconBase)
  818.         CloseLibrary(IconBase);
  819.  
  820.     if(DOSBase)
  821.         CloseLibrary((struct Library *)DOSBase);
  822.  
  823.     if(GadToolsBase)
  824.         CloseLibrary(GadToolsBase);
  825.  
  826.     if(GfxBase)
  827.         CloseLibrary((struct Library *)GfxBase);
  828.  
  829.     if(IntuitionBase)
  830.         CloseLibrary((struct Library *)IntuitionBase);
  831. }
  832.  
  833.  
  834.  
  835.  
  836.  
  837. /**********************************************************************/
  838. /*                         Handle all inputs                          */
  839. /**********************************************************************/
  840. void HandleInput(struct MsgPort *BrokerPort, CxObj *InputBroker)
  841. {
  842.     CxMsg            *MyMsg;
  843.     ULONG    BrokerSig    = (1L << BrokerPort->mp_SigBit),
  844.         MainSig, EditSig, PosSig, ManSig, MySig;
  845.     ULONG    MsgType, MsgID;
  846.     BOOL    QuitIT = FALSE;
  847.  
  848.  
  849.  
  850.     while(!QuitIT)
  851.     {
  852.             // Main window open ???
  853.  
  854.         if(MainWinHandle)
  855.             MainSig = (1L << MainWinHandle->UserPort->mp_SigBit);
  856.         else
  857.             MainSig = 0;
  858.  
  859.             // Edit window open ???
  860.  
  861.         if(EditWinHandle)
  862.             EditSig = (1L << EditWinHandle->UserPort->mp_SigBit);
  863.         else
  864.             EditSig = 0;
  865.  
  866.             // Position window open ???
  867.  
  868.         if(PosWinHandle)
  869.             PosSig = (1L << PosWinHandle->UserPort->mp_SigBit);
  870.         else
  871.             PosSig = 0;
  872.  
  873.             // Manual input window open ???
  874.  
  875.         if(ManWinHandle)
  876.             ManSig = (1L << ManWinHandle->UserPort->mp_SigBit);
  877.         else
  878.             ManSig = 0;
  879.  
  880.             // Wait for some signals
  881.  
  882.         MySig = Wait(BrokerSig | MainSig | EditSig | PosSig | ManSig | SIGBREAKF_CTRL_C);
  883.  
  884.  
  885.             // Go a CTRL-C ???
  886.  
  887.         if((MySig & SIGBREAKF_CTRL_C))
  888.             QuitIT = TRUE;
  889.  
  890.  
  891.             // Signal from Broker-Port ???
  892.  
  893.         if((MySig & BrokerSig))
  894.         {
  895.                 // Loop on all messages
  896.  
  897.             while((MyMsg = (CxMsg *)GetMsg(BrokerPort)))
  898.             {
  899.                 MsgType    = CxMsgType(MyMsg);
  900.                 MsgID    = CxMsgID(MyMsg);
  901.  
  902.                 ReplyMsg((struct Message *)MyMsg);
  903.  
  904.                 switch(MsgType)
  905.                 {
  906.                     case CXM_COMMAND :
  907.                     {
  908.                         switch(MsgID)
  909.                         {
  910.                                 // Remove...
  911.  
  912.                             case CXCMD_KILL :
  913.                             {
  914.                                 QuitIT = TRUE;
  915.                                 break;
  916.                             }
  917.                                 // On appear or unique, open main window
  918.  
  919.                             case CXCMD_APPEAR :
  920.                             case CXCMD_UNIQUE :
  921.                             {
  922.                                 if(!MainWinHandle)
  923.                                     OpenMainWin();
  924.                                 else
  925.                                     WindowToFront(MainWinHandle);
  926.                                 break;
  927.                             }
  928.                                 // Close all windows
  929.  
  930.                             case CXCMD_DISAPPEAR :
  931.                             {
  932.                                 CloseManWin();
  933.                                 CloseEditWin();
  934.                                 CloseMainWin();
  935.                                 break;
  936.                             }
  937.                                 // Disable ourself
  938.  
  939.                             case CXCMD_DISABLE :
  940.                             {
  941.                                     // Get semaphore, set state and flag
  942.  
  943.                                 ObtainSemaphore(&MySemaphore);
  944.                                 ActivateCxObj(InputBroker, FALSE);
  945.                                 Active = FALSE;
  946.                                 ReleaseSemaphore(&MySemaphore);
  947.                                 break;
  948.                             }
  949.                                 // Enable ourself
  950.  
  951.                             case CXCMD_ENABLE :
  952.                             {
  953.                                     // Get semaphore, set state and flag
  954.  
  955.                                 ObtainSemaphore(&MySemaphore);
  956.                                 ActivateCxObj(InputBroker, TRUE);
  957.                                 Active = TRUE;
  958.                                 ReleaseSemaphore(&MySemaphore);
  959.                                 break;
  960.                             }
  961.                         }
  962.                         break;
  963.                     }
  964.                         // Had a hotkey
  965.  
  966.                     case CXM_IEVENT :
  967.                     {
  968.                         switch(MsgID)
  969.                         {
  970.                                 // Open main window
  971.  
  972.                             case POPKEY :
  973.                             {
  974.                                 if(!MainWinHandle)
  975.                                     OpenMainWin();
  976.                                 else
  977.                                     WindowToFront(MainWinHandle);
  978.                                 break;
  979.                             }
  980.                         }
  981.                         break;
  982.                     }
  983.                 }
  984.             }
  985.         }
  986.  
  987.             // Message from mainwindow
  988.  
  989.         if(MainWinHandle && (MySig & MainSig))
  990.         {
  991.                 // Handle inputs
  992.  
  993.             if(HandleMainWin(&QuitIT))
  994.             {
  995.                     // Quit ???
  996.  
  997.                 if(!QuitIT)
  998.                     CloseMainWin();
  999.             }
  1000.         }
  1001.  
  1002.             // Message from edit window
  1003.  
  1004.         if(EditWinHandle && (MySig & EditSig))
  1005.         {
  1006.             if(HandleEditWin())
  1007.                 CloseEditWin();
  1008.         }
  1009.  
  1010.             // Message from manual input window
  1011.  
  1012.         if(ManWinHandle && (MySig & ManSig))
  1013.         {
  1014.             if(HandleManWin())
  1015.                 CloseManWin();
  1016.         }
  1017.  
  1018.             // Message from position window
  1019.  
  1020.         if(PosWinHandle && (MySig & PosSig))
  1021.             HandlePosWin();
  1022.     }
  1023.  
  1024.         // Close all windows on exit
  1025.  
  1026.     CloseManWin();
  1027.     CloseEditWin();
  1028.     CloseMainWin();
  1029. }
  1030.